extends Sprite2D

# signal health_depleted

# var health = 10

var speed = 200
var angular_speed = PI
var screen_size

func _init():
	print("_init!!!")

func _enter_tree():
	print("_enter_tree!!!")

func _exit_tree():
	print("_exit_tree!!!")

func _ready():
	print("_ready!!!")
	# var timer = get_node("Timer")
	# timer.connect("timeout",Callable(self,"_on_Timer_timeout"))
	screen_size = get_viewport_rect().size
	print($Icon.position)
	print($Icon.position.normalized())
	print($Icon.global_position)
	print($Icon.to_global(Vector2(1, 1)))
	print($Icon.to_local(Vector2(100, 100)))

func _process(delta):
	# rotation += angular_speed * delta
	# var velocity = Vector2.UP.rotated(rotation) * speed
	# position += velocity * delta
	var velocity = Vector2.ZERO
	if Input.is_action_pressed("ui_right"):
		velocity.x += 1
	if Input.is_action_pressed("ui_left"):
		velocity.x -= 1
	if Input.is_action_pressed("ui_down"):
		velocity.y += 1
	if Input.is_action_pressed("ui_up"):
		velocity.y -= 1
	if velocity.length() <= 0:
		return
	velocity = velocity.normalized() * speed
	$Icon.global_position += velocity * delta
	$Icon.global_position.x = clamp($Icon.global_position.x, 0, screen_size.x)
	$Icon.global_position.y = clamp($Icon.global_position.y, 0, screen_size.y)

func _on_Button_pressed():
	set_process(not is_processing())
	
func _on_Timer_timeout():
	visible = not visible

func _on_Button2_pressed():
	self.get_parent().remove_child(self)
